<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:71:"E:\WWW\huzhanwang.cc\public/../application/admin\view\notice\index.html";i:1700558192;}*/ ?>
<!DOCTYPE html>

<html>

<head>

  <meta charset="utf-8">

  <title>网站公告列表</title>

  <meta name="renderer" content="webkit">

  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">

  <link rel="stylesheet" href="/static/component/pear/css/pear.css" />

  <link rel="stylesheet" href="/static/admin/layuiadmin/style/admin.css" media="all">

</head>

<body>

<style>
  

</style>

  <div class="layui-fluid">   

    <div class="layui-card">

      <div class="layui-form layui-card-header layuiadmin-card-header-auto">

        <div class="layui-form-item">

          <style type="text/css">
            .layui-form-item .layui-inline {
                margin-bottom: 5px;
                margin-right: 0px;
            }
            .layui-table-cell {
                /*height: 51px;
                line-height: 51px;*/
              }
          </style>

            <label class="layui-form-label">筛选条件:</label>

            <div class="layui-inline" style="width: 200px;">
              <input type="text" class="layui-input" name="name" placeholder="请输入标题">
            </div>
     
           <!--  <div class="layui-inline">
              <div class="layui-input-inline">
                <input type="text" name="time" id="date" placeholder="请选择提交时间" autocomplete="off" class="layui-input">
              </div>
            </div> -->
         
          <div class="layui-inline">

            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">

              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>

            </button>

            

          </div>

        </div>

      </div>

      

      <div class="layui-card-body">

        <div style="padding-bottom: 10px;">
              <button class="layui-btn pear-btn-primary pear-btn-md layuiadmin-btn-admin" data-type="add">添加</button>
        </div>

        <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table> 

        <script type="text/html" id="switchTpl">

          <input type="checkbox" name="type" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? "checked" : "" }}>

        </script>

        <script type="text/html" id="table-useradmin-admin"> 
           <a class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"  value=" {{ d.id }}">&nbsp;&nbsp;修改&nbsp;&nbsp;</a>
           <!-- <a class="pear-btn pear-btn-normal pear-btn-xs" lay-event="detail"  value=" {{ d.id }}">&nbsp;&nbsp;详情&nbsp;&nbsp;</a> -->
           <a class="pear-btn pear-btn-danger pear-btn-sm" lay-event="del" value=" {{ d.id }}">&nbsp;&nbsp;删除&nbsp;&nbsp;</a>
        </script>

      </div>

    </div>

  </div>


   <style type="text/css">

/*   tbody .layui-table-cell{

    height:100px;


    line-height: 100px;

}*/

 </style>

 <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script> 

  <script>

  layui.use(['table', 'form', 'jquery','common','laydate'], function() {

    var $ = layui.$

    ,form = layui.form
    ,upload = layui.upload

    ,table = layui.table;

    var laydate = layui.laydate;

    var can={name:"",time:"",arr:''};

     laydate.render({ 

      elem: '#date',
      type:'date'

      ,range: '~' //或 range: '~' 来自定义分割字符

    });

    form.on('switch(sexDemo)', function(obj){

      var id=this.value;

      $.ajax({

           type: "POST",

           url: "<?php echo url('/admin/notice/up_status'); ?>?id="+id,

           data:"",

           success: function(msg){

            console.log(msg)

            if(msg==1){

             layer.msg("设置成功", {

                  offset: '15px'

                  ,icon: 1

                  ,time: 1000

                });

            }else if(msg==2){

              layer.msg("设置失败", {

                  offset: '15px'

                  ,icon: 2

                  ,time: 1000

                });

            }else if(msg==3){

              layer.msg("设置成功", {

                  offset: '15px'

                  ,icon: 1

                  ,time: 1000

                });

            }else{

              layer.msg("设置失败", {

                  offset: '15px'

                  ,icon: 2

                  ,time: 1000

                });

            }

           }

        });

      // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);

    });
 table.render({

    elem: '#LAY-user-back-manage'

    ,url:'<?php echo url('/admin/notice/lst'); ?>?type=2'

    ,contentType: 'application/json'

    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增

    ,request: {

      pageName: 'page' //页码的参数名称，默认：page

      ,limitName: 'limit' //每页数据量的参数名，默认：limit

    },

    cols: [[
      {field:'title', title: '标题',}   
      ,{field:'status', width:150, title: '状态',templet: '#switchTpl', unresize: true} 
      ,{field:'addtime', title: '添加时间' ,width:180}
      ,{fixed: 'right',width:220, title: '操作',templet: '#table-useradmin-admin'}
    ]]

    

    ,even: true

    ,page: true

    ,request: {

      pageName: 'page' //页码的参数名称，默认：page

      ,limitName: 'limit' //每页数据量的参数名，默认：limit

    }

    ,method:'post'

  });

    //监听搜索

    form.on('submit(LAY-user-back-search)', function(data){

      can = data.field;

      console.log(can);

      //执行重载

      table.reload('LAY-user-back-manage', {

        where: can

        ,url:'<?php echo url('/admin/notice/lst'); ?>?type=2'

        ,contentType: 'application/json'

        ,page: true

      });

    });



  //监听工具条

  table.on('tool(LAY-user-back-manage)', function(obj){

    var data = obj.data;

    var arr_id=[];

    arr_id.push(data.id);

    console.log(arr_id);

    if(obj.event === 'del'){

      layer.confirm('真的要删除吗', function(index){
        //执行 Ajax 后重载
        $.ajax({

           type: "POST",

           url: "<?php echo url('/admin/notice/do_del'); ?>",

           data:{id:arr_id},

           success: function(res){

            if(res.code==1){

             layer.msg(res.msg, {

                  offset: '15px'

                  ,icon: 1

                  ,time: 1000

                });
              obj.del();
              table.reload('LAY-user-back-manage');
            }else{
              layer.msg(res.msg, {

                  offset: '15px'

                  ,icon: 2

                  ,time: 1000

                });

            }

           }

        });

        // table.reload('LAY-user-back-manage');

         
          layer.close(index);

        });

    }else if(obj.event=='edit'){  //修改
      var id=data.id;
      layer.open({
          type: 2
          ,title: '修改'
          ,content: "<?php echo url('/admin/notice/update'); ?>?id="+id
          ,maxmin: true
          ,area:['70%', '90%']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
            ,submitID = 'LAY-user-front-submit'
            ,submit = layero.find('iframe').contents().find('#'+ submitID);

            //监听提交
            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
              var field = data.field; //获取提交的字段
              // layer.alert(JSON.stringify(data.field), {
              //   title: '最终的提交信息'
              // })
              
              $.ajax({
               type: "POST",
               url: "<?php echo url('/admin/notice/update'); ?>?id="+id,
               data: field,
               success: function(res){
                 if(res.code==1){
                    layer.msg(res.msg, {
                      offset: '15px'
                      ,icon: 1
                      ,time: 1000
                    });
                    table.reload('LAY-user-back-manage');
                  layer.close(index); //关闭弹层
                 }else{
                    layer.msg(res.msg, {
                    offset: '15px'
                    ,icon: 2
                    ,time: 1000
                  });
                 }
               }
            });
              
            });  
            
            submit.trigger('click');
          }
        });
    }else if(obj.event=='detail'){  
      var id=data.id;
        layer.open({
          type: 2, 
          title: '详情',
          content: "<?php echo url('/admin/notice/detail'); ?>?id="+id,
          maxmin: true,
          area: ['60%', '90%']
        });
    }


  });

    //事件

    var active = {
      add: function(){

        layer.open({

          type: 2

          ,title: '添加'

          ,content: "<?php echo url('/admin/notice/add'); ?>"

          ,maxmin: true

          ,area: ['70%', '90%']

          ,btn: ['确定', '取消']

          ,yes: function(index, layero){

            var iframeWindow = window['layui-layer-iframe'+ index]

            ,submitID = 'LAY-user-front-submit'

            ,submit = layero.find('iframe').contents().find('#'+ submitID);



            //监听提交

            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){

              var field = data.field; //获取提交的字段

              $.ajax({

               type: "POST",

               url: "<?php echo url('/admin/notice/add'); ?>?type=2",

               data: field,

               success: function(res){

                 if(res.code==1){

                    layer.msg(res.msg, {

                      offset: '15px'

                      ,icon: 1

                      ,time: 1000

                    });

                    layer.close(index); //关闭弹层
                     table.reload('LAY-user-back-manage'); //数据刷新
                 }else{

                  layer.msg(res.msg, {

                    offset: '15px'

                    ,icon: 2

                    ,time: 1000

                  });

                 }

               }



            });
            });  
             submit.trigger('click');

          }

        }); 

      },
     

    }  
     //监听状态操作
    form.on('switch(status)', function(obj){
      var id=this.value;
      $.ajax({
           type: "POST",
           url: "<?php echo url('/admin/notice/up_status'); ?>?id="+id,
           data:"",
           success: function(msg){
            console.log(msg)
            if(msg==1){
             layer.msg("禁用成功", {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
            }else if(msg==2){
              layer.msg("禁用失败", {
                  offset: '15px'
                  ,icon: 2
                  ,time: 1000
                });
            }else if(msg==3){
              layer.msg("启用成功", {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
            }else{
              layer.msg("启用失败", {
                  offset: '15px'
                  ,icon: 2
                  ,time: 1000
                });
            }
           }
        });
      // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
    });

    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){

      var type = $(this).data('type');

      active[type] ? active[type].call(this) : '';

    });

  });

  </script>

</body>

</html>



